package com.sun.dream.fish.service.impl;

import com.sun.dream.fish.entity.TRoleMenuEntity;
import com.sun.dream.fish.mapper.TRoleMenuMapper;
import com.sun.dream.fish.service.TRoleMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.dream.fish.util.ResponseUtil;
import com.sun.dream.fish.vo.ResultVO;
import com.sun.dream.fish.vo.back.RoleMenuVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ljl
 * @since 2023-12-18
 */
@Service
public class TRoleMenuServiceImpl extends ServiceImpl<TRoleMenuMapper, TRoleMenuEntity> implements TRoleMenuService {

    @Override
    public ResultVO saveRoleMenu(RoleMenuVO roleMenuVO) {
        try {
            List<TRoleMenuEntity> collect = roleMenuVO.getMenuList().stream().map(data -> {
                TRoleMenuEntity tRoleMenuEntity = new TRoleMenuEntity();
                tRoleMenuEntity.setRoleId(roleMenuVO.getRoleId());
                tRoleMenuEntity.setMenuId(data.getMenuId());
                tRoleMenuEntity.setStatus(data.getStatus());
                return tRoleMenuEntity;
            }).collect(Collectors.toList());
            saveBatch(collect);
        } catch (Exception e) {
            log.error("[TRoleMenuService]异常， ", e);
            return ResponseUtil.fail();
        }
        return ResponseUtil.ok();
    }
}
